package com.altekis.kanbankaze.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.ScriptElement;
import com.google.gwt.event.dom.client.LoadEvent;
import com.google.gwt.event.dom.client.LoadHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

/**
 * Board View
 * 
 */
public class KanbanView extends Composite implements KanbanPresenter.Display {

	interface KanbanViewUiBinder extends UiBinder<Widget, KanbanView> {
	}

	private static KanbanViewUiBinder uiBinder = GWT
			.create(KanbanViewUiBinder.class);

	@UiField
	Button loginButton;
	@UiField
	TextBox loginTextBox;
	@UiField
	AbsolutePanel panel;
	@UiField
	FlowPanel toolbar;

	public KanbanView() {
		initWidget(uiBinder.createAndBindUi(this));
		drawPlusOne();
	}

	@Override
	public HandlerRegistration addLoadHandler(LoadHandler handler) {
		return addDomHandler(handler, LoadEvent.getType());
	}

	private void drawPlusOne() {
		String s = "<g:plusone href=\"http://www.kanbankaze.com\"></g:plusone>";
		HTMLPanel h = new HTMLPanel("span", s);
		toolbar.add(h);

		Document doc = Document.get();
		ScriptElement script = doc.createScriptElement();
		script.setSrc("https://apis.google.com/js/plusone.js");
		script.setType("text/javascript");
		script.setLang("javascript");
		doc.getBody().appendChild(script);
	}

	public Button getLoginButton() {
		return loginButton;
	}

	@Override
	public HasValue<String> getLoginTextBox() {
		return loginTextBox;
	}

	public AbsolutePanel getPanel() {
		return panel;
	}

	/**
	 * @return the toolbar
	 */
	public FlowPanel getToolbar() {
		return toolbar;
	}
}
